import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/config/index.dart';
import 'package:yp/pages/mall_app/goods_detail/item/image_widget.dart';
import 'package:yp/services/api.dart';
import 'package:yp/utils/util.dart';
import 'package:yp/widgets/index.dart';

import '../../../../helper.dart';
import '../../../../router.dart';
import 'logic.dart';
import 'state.dart';

class FontSaleDetailPage extends StatefulWidget {
  FontSaleDetailPage({Key key}) : super(key: key);

  @override
  _FontSaleDetailPageState createState() => _FontSaleDetailPageState();
}

class _FontSaleDetailPageState extends State<FontSaleDetailPage> {
  final Color white = const Color(0xffffffff);
  GlobalKey<ImageWidgetState> imageWidgetKey = GlobalKey();
  GlobalKey _richContentLayoutKey = GlobalKey();
  final logic = Get.put(FontSaleDetailLogic());
  final state = Get.find<FontSaleDetailLogic>().state;
  bool _kIsWeb = kIsWeb;

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: FontSaleDetailLogic(),
        builder: (logic) {
          final FontSaleDetailState state = logic.state;
          Size size = MediaQuery.of(context).size;
          return Scaffold(
            appBar: YPNavigationBar(
              '预售订单',
              backBtnColor: white,
              backgroundColor: EsColors.Primary,
              titleColor: white,
            ),
            body: state.details == null
                ? Center(
                    child: Text('暂无数据'),
                  )
                : Container(
                    color: const Color(0xfff5f5f5),
                    height: size.height,
                    child: Stack(
                      children: [
                        SingleChildScrollView(
                          child: Column(
                            children: [
                              /// 图片
                              state.details['image_default_id'] != null
                                  ? Container(
                                      width: size.width,
                                      height: size.width,
                                      color: const Color(0xffffffff),
                                      child: Swiper(
                                        itemBuilder:
                                            (BuildContext context, int index) {
                                          return CachedNetworkImage(
                                            imageUrl: state
                                                .details['image_default_id'],
                                            errorWidget:
                                                (context, url, error) =>
                                                    Icon(Icons.error),
                                            fit: BoxFit.fill,
                                          );
                                        },
                                        itemCount: 1,
                                        viewportFraction: 1,
                                        scale: 1,
                                        pagination: SwiperPagination(),
                                        // autoplay: true,
                                      ),
                                    )
                                  : SizedBox(),

                              /// 倒计时
                              Container(
                                decoration: BoxDecoration(
                                  gradient: LinearGradient(colors: const [
                                    Color(0xff3C2F2E),
                                    Color(0xff241715)
                                  ]),
                                ),
                                padding: const EdgeInsets.symmetric(
                                    vertical: 13, horizontal: 12),
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.end,
                                      children: [
                                        Padding(
                                          padding:
                                              const EdgeInsets.only(bottom: 6),
                                          child: Text(
                                            '￥',
                                            style: TextStyle(
                                                color: white, fontSize: 12),
                                          ),
                                        ),
                                        Text(
                                          toConstraintLen(
                                              state.details['pre_price'], 3),
                                          style: TextStyle(
                                            color: white,
                                            fontSize: 40,
                                            // fontWeight: FontWeight.bold,
                                          ),
                                        ),
                                      ],
                                    ),
                                    Expanded(
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          Container(
                                            decoration: BoxDecoration(
                                              color: white,
                                              borderRadius:
                                                  BorderRadius.circular(15),
                                            ),
                                            margin:
                                                const EdgeInsets.only(left: 3),
                                            padding: const EdgeInsets.only(
                                                left: 7, right: 7, bottom: 1),
                                            child: Text(
                                              // '定金',
                                              "预付",
                                              style: TextStyle(fontSize: 12),
                                            ),
                                          ),
                                          Column(
                                            children: [
                                              Text(
                                                '距结束',
                                                style: TextStyle(
                                                    color:
                                                        const Color(0xffC99F4F),
                                                    fontSize: 13),
                                              ),
                                              Text(
                                                state.countContent,
                                                style: TextStyle(
                                                  color:
                                                      const Color(0xffC99F4F),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              ),

                              Container(
                                color: white,
                                padding: const EdgeInsets.symmetric(
                                    vertical: 20, horizontal: 12),
                                alignment: Alignment.centerLeft,
                                margin: const EdgeInsets.only(bottom: 10),
                                child: Text(
                                  state.details['item_name'] ?? '',
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(fontSize: 16),
                                ),
                              ),

                              /// 说明
                              Container(
                                color: white,
                                padding: const EdgeInsets.symmetric(
                                    vertical: 12, horizontal: 12),
                                margin: const EdgeInsets.only(bottom: 60),
                                alignment: Alignment.topLeft,
                                child: Column(
                                  children: [
                                    yushouhuodongshijian(),//活动时间
                                    SizedBox(height: 20),
                                    _playRulesWidget(title: '配送方式', data: '快递'),
                                    SizedBox(height: 20),
                                    _playRulesWidget(
                                        title: '预售说明',
                                        data:
                                            '预售价格${toConstraintLen((state.details['due_prce'] ?? 0) + (state.details['pre_price'] ?? 0), 3)},付定金${toConstraintLen(state.details['pre_price'], 3)},尾款需付${toConstraintLen(state.details['due_prce'], 3)},如有优惠券可在尾款使用',
                                        widget:Container(
                                          child: GestureDetector(
                                            onTap: (){
                                              showDialog<bool>(
                                                context: context,
                                                builder: (context) {
                                                  return AlertDialog(
                                                    title: Center(child: Text("支付说明"),),
                                                    //title 的内边距，默认 left: 24.0,top: 24.0, right 24.0
                                                    //默认底部边距 如果 content 不为null 则底部内边距为0
                                                    //            如果 content 为 null 则底部内边距为20
                                                    titlePadding: EdgeInsets.all(10),
                                                    //标题文本样式
                                                    titleTextStyle: TextStyle(color: Colors.black87, fontSize: 16),
                                                    //中间显示的内容
                                                    content: Text("定金预售定金只支持微信和购物卡不支持积分、优惠券,尾款支持积分、优惠券、购物卡和微信支付。付定金期间内不支持退定金,若需退款请在支付完尾款后申请退款。"),
                                                    //中间显示的内容边距
                                                    //默认 EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0)
                                                    contentPadding: EdgeInsets.all(10),
                                                    //中间显示内容的文本样式
                                                    contentTextStyle: TextStyle(color: Colors.black54, fontSize: 14),
                                                    //底部按钮区域
                                                    actions: <Widget>[
                                                      Container(),
                                                      FlatButton(
                                                        child: Center(child:Text("知道了")),
                                                        onPressed: () {
                                                          //关闭 返回true
                                                          Navigator.of(context).pop(true);
                                                        },
                                                      ),
                                                      Container(),
                                                    ],
                                                  );
                                                },
                                              );
                                            },
                                            child: Icon(
                                              Icons.error_outline,
                                              size: 20,
                                              color: const Color(0xff999999),
                                            ),
                                          ),
                                        )
                                        ),
                                    SizedBox(height: 20),
                                    // _playRulesWidget(
                                    //     title: '发货时间', data: '付尾款20天内'),
                                    _playRulesWidget(
                                        title: '发货时间',
                                        data: state.deliveryStartTime != null &&
                                                state.deliveryEndTime != null
                                            ? '${state.deliveryStartTime}-${state.deliveryEndTime}'
                                            : '暂无数据'),
                                    _divider(10),
                                    shopInfoWidget(), // 店铺查看
                                    _divider(10),
                                    _recommendGoodsModule(), // 推荐商品
                                    _divider(10),
                                    richTextDetailLayout(), // 图文详情
                                    _divider(60),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                        Positioned(
                          bottom: 0,
                          width: size.width,
                          height: 50,
                          child: Container(
                            decoration: BoxDecoration(
                              color: white,
                              border: Border(
                                top: BorderSide(color: const Color(0xffefefef)),
                              ),
                            ),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  children: [
                                    SizedBox(width: 20),
                                    GestureDetector(
                                      onTap: () {
                                        if (SpUtil.getString('token') == null ||
                                            SpUtil.getString('token').isEmpty) {
                                          Get.toNamed(RouteConfig.mallLogin);
                                          //     .then((value) {
                                          //   if (SpUtil.getString('token') !=
                                          //           null &&
                                          //       SpUtil.getString('token')
                                          //           .isNotEmpty) {
                                          //     logic.requestDetail();
                                          //   }
                                          // });
                                        } else {
                                          if (state.favorite_sign == false) {
                                            var params = {
                                              "use_platform": 2,
                                              "style_num_id":
                                                  state.details['style_num_id'],
                                              "ec_shop_num_id":
                                                  state.details['shop_num_id'],
                                              "access_token":
                                                  SpUtil.getString("token")
                                            };
                                            Api.addGoodsToFavorite(params)
                                                .listen((event) {
                                              if (event['code'] == 0) {
                                                toast('加入收藏成功');
                                                state.favorite_sign = true;
                                              }
                                              imageWidgetKey.currentState
                                                  .onPressed(
                                                      state.favorite_sign);
                                            });
                                          } else {
                                            var params = {
                                              "style_num_id":
                                                  state.details['style_num_id'],
                                              "ec_shop_num_id":
                                                  state.details['shop_num_id'],
                                              'access_token':
                                                  SpUtil.getString('token'),
                                            };
                                            Api.collectListsDelete(params)
                                                .listen((event) {
                                              if (event['code'] == 0) {
                                                toast('取消收藏成功');
                                                state.favorite_sign = false;
                                              }
                                              imageWidgetKey.currentState
                                                  .onPressed(
                                                      state.favorite_sign);
                                            });
                                          }
                                          // logic.requestAddToFavorite();
                                        }
                                      },
                                      behavior: HitTestBehavior.opaque,
                                      child: ImageWidget(
                                        imageWidgetKey,
                                        state.favorite_sign,
                                      ),
                                    ),
                                    Offstage(
                                      offstage: state.keFuString == null ||
                                          state.keFuString == '',
                                      child: Padding(
                                        padding: EdgeInsets.only(
                                            left: 20, right: 20),
                                        child: GestureDetector(
                                          onTap: () {
                                            print('联系客服');
                                            if (kIsWeb) {
                                              webpay(
                                                  "https://ykf-webchat.7moor.com/wapchat.html?accessId=${state.keFuString}&fromUrl=&urlTitle=&language=ZHCN");
                                              return;
                                            }
                                            gotoHelpDesk();
                                          },
                                          behavior: HitTestBehavior.opaque,
                                          child: Image.asset(
                                            'assets/images/service_9.png',
                                            width: 20,
                                            height: 20,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                                InkWell(
                                  onTap: () {
                                    if (state.details['buy']!=true) {
                                      return;
                                    }
                                    logic.goSurplusShop();
                                  },
                                  child: Container(
                                    padding: const EdgeInsets.symmetric(
                                        horizontal: 20),
                                    color:state.details['buy']!=true?Color(0xffCCCCCC):EsColors.Primary,
                                    alignment: Alignment.center,
                                    child: Text(
                                      state.details['buy']!=true?'已售空':'付定金￥${toConstraintLen(state.details['pre_price'], 3)}',
                                      textAlign: TextAlign.center,
                                      style:
                                          TextStyle(fontSize: 17, color: white),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
          );
        });
  }
  gotoHelpDesk() {
    if (SpUtil.getString('token') == null ||
        SpUtil.getString('token').isEmpty) {
      Get.toNamed(RouteConfig.mallLogin, arguments: {
        'itemNumId': logic.itemNumId,
        'styleNumId': logic.styleNumId,
        'shopId': logic.shopId,
      }).then((value) {
        if (SpUtil.getString('token') != null &&
            SpUtil.getString('token').isNotEmpty) {

        }
      });
    } else {
      if (state.keFuString.isNotEmpty) {
        var otherParams = {
          "productInfo": {},
          // "peerId": "10052439",
          "nickName": "${SpUtil.getString('empeName')}",
        };
        var clientId = '${SpUtil.getInt('empeNumId')}';
        var kefubaseUrl =
            'https://7moor.zrhsh.com/wapchat.html?fromUrl=&urlTitle=&language=ZHCN';
        kefubaseUrl = kefubaseUrl +
            '&accessId=' +
            state.keFuString +
            '&otherParams=' +
            jsonEncode(otherParams) +
            '&clientId=' +
            clientId;
        if (kIsWeb) {
          webpay(
              kefubaseUrl  );
          return;
        }
        Get.toNamed(RouteConfig.webview, arguments: {
          "url":
          kefubaseUrl,
        });
      }
    }
  }
  Widget yushouhuodongshijian(){
    return Container(
      width: 375,
      margin: EdgeInsets.all(12),
      padding: EdgeInsets.all(12),
      decoration: BoxDecoration(
        color: Color.fromRGBO(237, 229, 250, 0.5),
        borderRadius:BorderRadius.circular(15),
      ),
      child: Row(
        mainAxisSize:MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            child: Column(
              children: [
                Text(
                  '1.付定金',
                  style: TextStyle(
                    fontSize: 12
                  ),
                ),
                Text(
                  state.details["pre_end_time"],
                  style: TextStyle(
                    fontSize: 12
                  ),
                ),
                Text(
                  '截至',
                  style: TextStyle(
                    fontSize: 12
                  ),
                )
              ],
            ),
          ),
          Center(
            child: Container(
              width: 30,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                border: new Border.all(color: Color(0xFF1C1C1C), width: 0.5),
                color: Color(0xFF9E9E9E),
                borderRadius: new BorderRadius.circular((20.0))
              ),
            ),
          ),
          Container(
            child: Column(
              children: [
                Text(
                  '2.付尾款',
                  style: TextStyle(
                    fontSize: 12
                  ),
                ),
                Text(
                  state.details["due_start_time"],
                  style: TextStyle(
                    fontSize: 12
                  ),
                ),
                Text(
                  '开始',
                  style: TextStyle(
                    fontSize: 12
                  ),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _playRulesWidget({
    String title,
    String data,
    Widget widget,
  }) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Padding(
          padding: const EdgeInsets.only(right: 15),
          child: Text(
            title,
            style: TextStyle(color: const Color(0xff999999), fontSize: 12),
          ),
        ),
       
        Expanded(
          child: Text.rich(
            TextSpan(
              children: [
                TextSpan(
                  text: data,
                  style: TextStyle(fontSize: 12),
                ),
                widget!=null?WidgetSpan(child: widget):TextSpan(),
              ]
            )
          ),
        ),
      ],
    );
  }
  //分隔控件
  Widget _divider(double height) {
    return Container(
      width: double.infinity,
      height: height,
      color: const Color(0xFFF3F4F6),
    );
  }

  Widget shopInfoWidget() {
    return state.shopInfos != null
        ? Container(
            color: const Color(0xffffffff),
            padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 15),
            child: InkWell(
              onTap: () {
                if (_kIsWeb) return;
                logic.goToThirdShop();
              },
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                      margin: const EdgeInsets.only(right: 10),
                      width: setWidth(100),
                      height: setWidth(100),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        color: const Color(0xfff4f4f4),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black12,
                            blurRadius: 2,
                          ),
                        ],
                      ),
                      child: Image.network(
                          state.shopInfos['ec_shop_logo'] == null ||
                                  state.shopInfos['ec_shop_logo'] == ''
                              ? Config.orderEmpty
                              : state.shopInfos['ec_shop_logo'])),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Expanded(
                              child: Text(
                                state.shopInfos['shop_name'] ?? '',
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: const Color(0xff333333),
                                  fontWeight: FontWeight.bold,
                                  fontSize: 15,
                                ),
                              ),
                            ),
                            _kIsWeb
                                ? SizedBox()
                                : Padding(
                                    padding: const EdgeInsets.only(right: 13),
                                    child: Image.asset(
                                      'assets/images/arrow_right.png',
                                      width: 20,
                                      height: 20,
                                    ),
                                  ),
                          ],
                        ),
                        SizedBox(height: 5),
                        _kIsWeb
                            ? SizedBox()
                            : Container(
                                decoration: BoxDecoration(
                                  border: Border.all(
                                    color: const Color(0xffCCCCCC),
                                  ),
                                  borderRadius: BorderRadius.circular(20),
                                ),
                                padding:
                                    const EdgeInsets.only(top: 3, bottom: 3),
                                width: 110,
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Container(
                                      width: 12,
                                      margin: const EdgeInsets.only(right: 6),
                                      child: Image.asset(
                                        'assets/images/shopLogo.png',
                                        fit: BoxFit.fill,
                                      ),
                                    ),
                                    Text(
                                      '进店逛逛',
                                      style: TextStyle(
                                        color: const Color(0xff333333),
                                      ),
                                    )
                                  ],
                                ),
                              ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          )
        : SizedBox();
  }

  // 推荐商品
  Widget _recommendGoodsModule() {
    if (state.recommendGoods == null || state.recommendGoods['lists'] == null) {
      return Container();
    }
    List list = state.recommendGoods['lists'];
    if (list == null || list.isEmpty) {
      return Container();
    }
    return Container(
      width: MediaQuery.of(context).size.width,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: const EdgeInsets.only(left: 5, right: 5),
            height: 200,
            child: ListView.builder(
              shrinkWrap: true,
              scrollDirection: Axis.horizontal,
              itemCount: list.length,
              itemBuilder: (context, index) {
                return _recommendGoodsItem(list[index]);
              },
            ),
          ),
        ],
      ),
    );
  }
  // 推荐商品 item
  Widget _recommendGoodsItem(var goods) {
    String imgUrl = goods['image_default_id'];
    String goodsName = goods['title'];
    String price1 = goods['price'].toString();
    String price2 = goods['mkt_price'].toString();
    bool soldOutBool = goods['style_store'] <= 0;

    return InkWell(
      onTap: () {
        print('！！！！！！！！！！  商品点击事件  ！！！！！！！！！！');
        print('goods = $goods');
        print('！！！！！！！！！！  商品点击事件  ！！！！！！！！！！');

        String itemNumId = goods['default_item_num_id']?.toString() ?? '';
        String styleNumId = goods['style_num_id']?.toString() ?? '';
        String shopId = goods['shop_num_id']?.toString() ?? '';
        String cat1Id = goods['cat1_id']?.toString() ?? '';
        String ecStyleNumId = goods['ec_style_num_id'].toString() ?? '';
        print('商品点击事件'
            'itemNumId = $itemNumId'
            'styleNumId = $styleNumId'
            'shopId = $shopId'
            'cat1Id = $cat1Id'
            'ecStyleNumId = $ecStyleNumId');

        Get.back();
        Get.toNamed(RouteConfig.goodsDetail, arguments: {
          'itemNumId': itemNumId,
          'styleNumId': styleNumId,
          'shopId': shopId,
          'cat1Id': cat1Id,
          'ecStyleNumId': ecStyleNumId,
          'typeIndex': goods['is_pre_sale'],
        });
      },
      child: Container(
        width: 120,
        padding: const EdgeInsets.symmetric(horizontal: 5),
        child: Column(
          children: [
            Stack(
              children: [
                CachedImage(
                  width: 110,
                  height: 110,
                  margin: EdgeInsets.zero,
                  scale: BoxFit.fill,
                  path: imgUrl,
                ),
                Positioned(
                  left: 25,
                  top: 25,
                  child: soldOutBool
                      ? Container(
                          width: 60,
                          height: 60,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: Color(0xffbbbbbb).withOpacity(0.7),
                            borderRadius: BorderRadius.circular(setWidth(60)),
                          ),
                          child: Text(
                            '售罄',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 15,
                            ),
                          ),
                        )
                      : SizedBox(),
                ),
              ],
            ),
            Padding(
              padding: const EdgeInsets.only(top: 10),
              child: Text(
                goodsName,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(fontSize: 12, color: Colors.black),
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 8),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.only(right: 8.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          RichText(
                              text: TextSpan(children: [
                            TextSpan(
                                text: '¥',
                                style: TextStyle(
                                  fontSize: 12,
                                  color: Config.mainColor,
                                )),
                            TextSpan(
                                text: price1,
                                style: TextStyle(
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold,
                                  color: Config.mainColor,
                                )),
                          ])),
                          Text(
                            price2,
                            style: TextStyle(
                              fontSize: 12,
                              color: const Color(0xFFCCCCCC),
                              decoration: TextDecoration.lineThrough,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                  _kIsWeb || goods['fresh_type'] == 8
                      ? SizedBox()
                      : GestureDetector(
                          onTap: () {
                            if (SpUtil.getString('token') == null ||
                                SpUtil.getString('token').isEmpty) {
                              Get.toNamed(RouteConfig.mallLogin, arguments: {
                                'itemNumId': logic.itemNumId,
                                'styleNumId': logic.styleNumId,
                                'shopId': logic.shopId,
                                // 'typeIndex': state.typeIndex,
                              }).then((value) {
                                if (SpUtil.getString('token') != null &&
                                    SpUtil.getString('token').isNotEmpty) {
                                  // logic.requestDetail();
                                }
                              });
                            } else {
                              if (!soldOutBool) {
                                String ecShopNumId =
                                    goods['shop_num_id']?.toString() ??
                                        SpUtil.getObject(
                                                Config.GET_SHOP_INFO)['shop_id']
                                            ?.toString();
                                String itemNumId =
                                    goods['default_item_num_id']?.toString();
                                String styleNumId =
                                    goods['style_num_id']?.toString();
                                String ecStyleNumId =
                                    goods['ec_style_num_id']?.toString();
                                logic.requestAddGoods(ecShopNumId, itemNumId,
                                    styleNumId, ecStyleNumId);
                              }
                            }
                          },
                          child: Image.asset(
                            'assets/images/add_shopping_cart.png',
                            width: 20,
                            height: 20,
                            color: !soldOutBool
                                ? Color(0xffEA5504)
                                : Color(0xffcccccc),
                          ),
                        )
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
  // 图文详情
  Widget richTextDetailLayout() {
    if (state.richText == null ||
        state.richText.toString().isEmpty ||
         state.richText['wap_desc'] == null ||
         state.richText['wap_desc'].toString().isEmpty
        ) {
      return Container(
        key: _richContentLayoutKey,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.only(left: 10, top: 15, bottom: 10),
              child: Text(
                '图文详情',
                style: TextStyle(
                  fontSize: 16,
                  color: const Color(0xFF222222),
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
          ],
        ),
      );
    }
    return Container(
      key: _richContentLayoutKey,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.only(left: 10, top: 15, bottom: 10),
            child: Text(
              '图文详情',
              style: TextStyle(
                fontSize: 16,
                color: const Color(0xFF222222),
                fontWeight: FontWeight.w500,
              ),
            ),
          ),

          // 商品详情头部广告
          // state.advertising.length > 0
          //     ? Container(
          //         margin: EdgeInsets.only(right: 20.w, left: 20.w),
          //         child: Column(
          //           children: _newList(state.advertising, 0),
          //         ),
          //       )
          //     : Container(),
          //  state.richText == null ||state.richText['head_desc'] == null?Container():Html(data: state.richText['head_desc'].toString()),
          // 图文详情头部
          // Html(data: state.richText['head_desc'].toString()),
          _detailHeader(),
          // // 图文详情中部
          // // Html(data: state.richText['wap_desc'].toString()),
          _detailWapDesc(),
          // 图文详情尾部
          // Html(data: state.richText['end_desc'].toString()),
          _detailEndDesc(),
          // 商品详情尾部广告
          // state.advertising.length > 0
          //     ? Container(
          //         margin: EdgeInsets.only(right: 20.w, left: 20.w),
          //         child: Column(
          //           children: _newList(state.advertising, 2),
          //         ),
          //       )
          //     : Container(),
        ],
      ),
    );
  }

  // 图文详情头部
  Widget _detailHeader() {
    if (state.richText == null ||
        state.richText.toString().isEmpty ||
        state.richText['head_desc'] == null ||
        state.richText['head_desc'].toString().isEmpty) {
      return Container();
    }
    print(state.richText['head_desc'].toString());
    return Html(data: state.richText['head_desc']);
  }

  // 图文详情中部
  Widget _detailWapDesc() {
    if (state.richText == null ||
        state.richText.toString().isEmpty ||
        state.richText['wap_desc'] == null ||
        state.richText['wap_desc'].toString().isEmpty) {
      return Container();
    }
    return Html(data: state.richText['wap_desc'].toString());
  }

  // 图文详情尾部
  Widget _detailEndDesc() {
    if (state.richText == null ||
        state.richText.toString().isEmpty ||
        state.richText['end_desc'] == null ||
        state.richText['end_desc'].toString().isEmpty) {
      return Container();
    }
    return Html(data: state.richText['end_desc'].toString());
  }

}
